﻿using System;
using UnityEngine;

namespace UnityStandardAssets.CinematicEffects
{
	// Token: 0x02000477 RID: 1143
	[ExecuteInEditMode]
	[AddComponentMenu("Image Effects/Cinematic/Depth Of Field")]
	[RequireComponent(typeof(Camera))]
	public class DepthOfField : MonoBehaviour
	{
		// Token: 0x170001F3 RID: 499
		// (get) Token: 0x06001820 RID: 6176 RVA: 0x00066BE1 File Offset: 0x00064FE1
		public Shader filmicDepthOfFieldShader
		{
			get
			{
				if (this.m_FilmicDepthOfFieldShader == null)
				{
					this.m_FilmicDepthOfFieldShader = Shader.Find("Hidden/DepthOfField/DepthOfField");
				}
				return this.m_FilmicDepthOfFieldShader;
			}
		}

		// Token: 0x170001F4 RID: 500
		// (get) Token: 0x06001821 RID: 6177 RVA: 0x00066C0A File Offset: 0x0006500A
		public Shader medianFilterShader
		{
			get
			{
				if (this.m_MedianFilterShader == null)
				{
					this.m_MedianFilterShader = Shader.Find("Hidden/DepthOfField/MedianFilter");
				}
				return this.m_MedianFilterShader;
			}
		}

		// Token: 0x170001F5 RID: 501
		// (get) Token: 0x06001822 RID: 6178 RVA: 0x00066C33 File Offset: 0x00065033
		public Shader textureBokehShader
		{
			get
			{
				if (this.m_TextureBokehShader == null)
				{
					this.m_TextureBokehShader = Shader.Find("Hidden/DepthOfField/BokehSplatting");
				}
				return this.m_TextureBokehShader;
			}
		}

		// Token: 0x170001F6 RID: 502
		// (get) Token: 0x06001823 RID: 6179 RVA: 0x00066C5C File Offset: 0x0006505C
		public Material filmicDepthOfFieldMaterial
		{
			get
			{
				if (this.m_FilmicDepthOfFieldMaterial == null)
				{
					this.m_FilmicDepthOfFieldMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(this.filmicDepthOfFieldShader);
				}
				return this.m_FilmicDepthOfFieldMaterial;
			}
		}

		// Token: 0x170001F7 RID: 503
		// (get) Token: 0x06001824 RID: 6180 RVA: 0x00066C86 File Offset: 0x00065086
		public Material medianFilterMaterial
		{
			get
			{
				if (this.m_MedianFilterMaterial == null)
				{
					this.m_MedianFilterMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(this.medianFilterShader);
				}
				return this.m_MedianFilterMaterial;
			}
		}

		// Token: 0x170001F8 RID: 504
		// (get) Token: 0x06001825 RID: 6181 RVA: 0x00066CB0 File Offset: 0x000650B0
		public Material textureBokehMaterial
		{
			get
			{
				if (this.m_TextureBokehMaterial == null)
				{
					this.m_TextureBokehMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(this.textureBokehShader);
				}
				return this.m_TextureBokehMaterial;
			}
		}

		// Token: 0x170001F9 RID: 505
		// (get) Token: 0x06001826 RID: 6182 RVA: 0x00066CDC File Offset: 0x000650DC
		public ComputeBuffer computeBufferDrawArgs
		{
			get
			{
				if (this.m_ComputeBufferDrawArgs == null)
				{
					this.m_ComputeBufferDrawArgs = new ComputeBuffer(1, 16, ComputeBufferType.IndirectArguments);
					this.m_ComputeBufferDrawArgs.SetData(new int[]
					{
						0,
						1,
						0,
						0
					});
				}
				return this.m_ComputeBufferDrawArgs;
			}
		}

		// Token: 0x170001FA RID: 506
		// (get) Token: 0x06001827 RID: 6183 RVA: 0x00066D29 File Offset: 0x00065129
		public ComputeBuffer computeBufferPoints
		{
			get
			{
				if (this.m_ComputeBufferPoints == null)
				{
					this.m_ComputeBufferPoints = new ComputeBuffer(90000, 28, ComputeBufferType.Append);
				}
				return this.m_ComputeBufferPoints;
			}
		}

		// Token: 0x06001828 RID: 6184 RVA: 0x00066D50 File Offset: 0x00065150
		private void OnEnable()
		{
			if (!ImageEffectHelper.IsSupported(this.filmicDepthOfFieldShader, true, true, this) || !ImageEffectHelper.IsSupported(this.medianFilterShader, true, true, this))
			{
				base.enabled = false;
				return;
			}
			if (ImageEffectHelper.supportsDX11 && !ImageEffectHelper.IsSupported(this.textureBokehShader, true, true, this))
			{
				base.enabled = false;
				return;
			}
			this.ComputeBlurDirections(true);
			base.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
		}

		// Token: 0x06001829 RID: 6185 RVA: 0x00066DCC File Offset: 0x000651CC
		private void OnDisable()
		{
			this.ReleaseComputeResources();
			if (this.m_FilmicDepthOfFieldMaterial != null)
			{
				UnityEngine.Object.DestroyImmediate(this.m_FilmicDepthOfFieldMaterial);
			}
			if (this.m_TextureBokehMaterial != null)
			{
				UnityEngine.Object.DestroyImmediate(this.m_TextureBokehMaterial);
			}
			if (this.m_MedianFilterMaterial != null)
			{
				UnityEngine.Object.DestroyImmediate(this.m_MedianFilterMaterial);
			}
			this.m_FilmicDepthOfFieldMaterial = null;
			this.m_TextureBokehMaterial = null;
			this.m_MedianFilterMaterial = null;
			this.m_RTU.ReleaseAllTemporaryRenderTextures();
		}

		// Token: 0x0600182A RID: 6186 RVA: 0x00066E54 File Offset: 0x00065254
		private void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			if (this.medianFilterMaterial == null || this.filmicDepthOfFieldMaterial == null)
			{
				Graphics.Blit(source, destination);
				return;
			}
			if (this.settings.visualizeFocus)
			{
				Vector4 vector;
				Vector4 vector2;
				this.ComputeCocParameters(out vector, out vector2);
				this.filmicDepthOfFieldMaterial.SetVector("_BlurParams", vector);
				this.filmicDepthOfFieldMaterial.SetVector("_BlurCoe", vector2);
				Graphics.Blit(null, destination, this.filmicDepthOfFieldMaterial, 5);
			}
			else
			{
				this.DoDepthOfField(source, destination);
			}
			this.m_RTU.ReleaseAllTemporaryRenderTextures();
		}

		// Token: 0x0600182B RID: 6187 RVA: 0x00066EF0 File Offset: 0x000652F0
		private void DoDepthOfField(RenderTexture source, RenderTexture destination)
		{
			this.m_CurrentQualitySettings = DepthOfField.QualitySettings.presetQualitySettings[(int)this.settings.filteringQuality];
			float num = (float)source.height / 720f;
			float num2 = num;
			float num3 = Mathf.Max(this.focus.nearBlurRadius, this.focus.farBlurRadius) * num2 * 0.75f;
			float num4 = this.focus.nearBlurRadius * num;
			float num5 = this.focus.farBlurRadius * num;
			float num6 = Mathf.Max(num4, num5);
			DepthOfField.ApertureShape apertureShape = this.settings.apertureShape;
			if (apertureShape != DepthOfField.ApertureShape.Hexagonal)
			{
				if (apertureShape == DepthOfField.ApertureShape.Octogonal)
				{
					num6 *= 1.15f;
				}
			}
			else
			{
				num6 *= 1.2f;
			}
			if (num6 < 0.5f)
			{
				Graphics.Blit(source, destination);
				return;
			}
			int width = source.width / 2;
			int height = source.height / 2;
			Vector4 vector = new Vector4(num4 * 0.5f, num5 * 0.5f, 0f, 0f);
			RenderTexture temporaryRenderTexture = this.m_RTU.GetTemporaryRenderTexture(width, height, 0, RenderTextureFormat.ARGBHalf, FilterMode.Bilinear);
			RenderTexture temporaryRenderTexture2 = this.m_RTU.GetTemporaryRenderTexture(width, height, 0, RenderTextureFormat.ARGBHalf, FilterMode.Bilinear);
			Vector4 vector2;
			Vector4 vector3;
			this.ComputeCocParameters(out vector2, out vector3);
			this.filmicDepthOfFieldMaterial.SetVector("_BlurParams", vector2);
			this.filmicDepthOfFieldMaterial.SetVector("_BlurCoe", vector3);
			Graphics.Blit(source, temporaryRenderTexture2, this.filmicDepthOfFieldMaterial, 4);
			RenderTexture renderTexture = temporaryRenderTexture2;
			RenderTexture renderTexture2 = temporaryRenderTexture;
			if (this.shouldPerformBokeh)
			{
				RenderTexture temporaryRenderTexture3 = this.m_RTU.GetTemporaryRenderTexture(width, height, 0, RenderTextureFormat.ARGBHalf, FilterMode.Bilinear);
				Graphics.Blit(renderTexture, temporaryRenderTexture3, this.filmicDepthOfFieldMaterial, 1);
				this.filmicDepthOfFieldMaterial.SetVector("_Offsets", new Vector4(0f, 1.5f, 0f, 1.5f));
				Graphics.Blit(temporaryRenderTexture3, renderTexture2, this.filmicDepthOfFieldMaterial, 0);
				this.filmicDepthOfFieldMaterial.SetVector("_Offsets", new Vector4(1.5f, 0f, 0f, 1.5f));
				Graphics.Blit(renderTexture2, temporaryRenderTexture3, this.filmicDepthOfFieldMaterial, 0);
				this.textureBokehMaterial.SetTexture("_BlurredColor", temporaryRenderTexture3);
				this.textureBokehMaterial.SetFloat("_SpawnHeuristic", this.bokehTexture.spawnHeuristic);
				this.textureBokehMaterial.SetVector("_BokehParams", new Vector4(this.bokehTexture.scale * num2, this.bokehTexture.intensity, this.bokehTexture.threshold, num3));
				Graphics.SetRandomWriteTarget(1, this.computeBufferPoints);
				Graphics.Blit(renderTexture, renderTexture2, this.textureBokehMaterial, 1);
				Graphics.ClearRandomWriteTargets();
				DepthOfField.SwapRenderTexture(ref renderTexture, ref renderTexture2);
				this.m_RTU.ReleaseTemporaryRenderTexture(temporaryRenderTexture3);
			}
			this.filmicDepthOfFieldMaterial.SetVector("_BlurParams", vector2);
			this.filmicDepthOfFieldMaterial.SetVector("_BlurCoe", vector);
			RenderTexture renderTexture3 = null;
			if (this.m_CurrentQualitySettings.dilateNearBlur)
			{
				RenderTexture temporaryRenderTexture4 = this.m_RTU.GetTemporaryRenderTexture(width, height, 0, RenderTextureFormat.RGHalf, FilterMode.Bilinear);
				renderTexture3 = this.m_RTU.GetTemporaryRenderTexture(width, height, 0, RenderTextureFormat.RGHalf, FilterMode.Bilinear);
				this.filmicDepthOfFieldMaterial.SetVector("_Offsets", new Vector4(0f, num4 * 0.75f, 0f, 0f));
				Graphics.Blit(renderTexture, temporaryRenderTexture4, this.filmicDepthOfFieldMaterial, 2);
				this.filmicDepthOfFieldMaterial.SetVector("_Offsets", new Vector4(num4 * 0.75f, 0f, 0f, 0f));
				Graphics.Blit(temporaryRenderTexture4, renderTexture3, this.filmicDepthOfFieldMaterial, 3);
				this.m_RTU.ReleaseTemporaryRenderTexture(temporaryRenderTexture4);
				renderTexture3.filterMode = FilterMode.Point;
			}
			if (this.m_CurrentQualitySettings.prefilterBlur)
			{
				Graphics.Blit(renderTexture, renderTexture2, this.filmicDepthOfFieldMaterial, 6);
				DepthOfField.SwapRenderTexture(ref renderTexture, ref renderTexture2);
			}
			DepthOfField.ApertureShape apertureShape2 = this.settings.apertureShape;
			if (apertureShape2 != DepthOfField.ApertureShape.Circular)
			{
				if (apertureShape2 != DepthOfField.ApertureShape.Hexagonal)
				{
					if (apertureShape2 == DepthOfField.ApertureShape.Octogonal)
					{
						this.DoOctogonalBlur(renderTexture3, ref renderTexture, ref renderTexture2, num6);
					}
				}
				else
				{
					this.DoHexagonalBlur(renderTexture3, ref renderTexture, ref renderTexture2, num6);
				}
			}
			else
			{
				this.DoCircularBlur(renderTexture3, ref renderTexture, ref renderTexture2, num6);
			}
			DepthOfField.FilterQuality medianFilter = this.m_CurrentQualitySettings.medianFilter;
			if (medianFilter != DepthOfField.FilterQuality.Normal)
			{
				if (medianFilter == DepthOfField.FilterQuality.High)
				{
					Graphics.Blit(renderTexture, renderTexture2, this.medianFilterMaterial, 1);
					DepthOfField.SwapRenderTexture(ref renderTexture, ref renderTexture2);
				}
			}
			else
			{
				this.medianFilterMaterial.SetVector("_Offsets", new Vector4(1f, 0f, 0f, 0f));
				Graphics.Blit(renderTexture, renderTexture2, this.medianFilterMaterial, 0);
				DepthOfField.SwapRenderTexture(ref renderTexture, ref renderTexture2);
				this.medianFilterMaterial.SetVector("_Offsets", new Vector4(0f, 1f, 0f, 0f));
				Graphics.Blit(renderTexture, renderTexture2, this.medianFilterMaterial, 0);
				DepthOfField.SwapRenderTexture(ref renderTexture, ref renderTexture2);
			}
			this.filmicDepthOfFieldMaterial.SetVector("_BlurCoe", vector);
			this.filmicDepthOfFieldMaterial.SetVector("_Convolved_TexelSize", new Vector4((float)renderTexture.width, (float)renderTexture.height, 1f / (float)renderTexture.width, 1f / (float)renderTexture.height));
			this.filmicDepthOfFieldMaterial.SetTexture("_SecondTex", renderTexture);
			int pass = 11;
			if (this.shouldPerformBokeh)
			{
				RenderTexture temporaryRenderTexture5 = this.m_RTU.GetTemporaryRenderTexture(source.height, source.width, 0, source.format, FilterMode.Bilinear);
				Graphics.Blit(source, temporaryRenderTexture5, this.filmicDepthOfFieldMaterial, pass);
				Graphics.SetRenderTarget(temporaryRenderTexture5);
				ComputeBuffer.CopyCount(this.computeBufferPoints, this.computeBufferDrawArgs, 0);
				this.textureBokehMaterial.SetBuffer("pointBuffer", this.computeBufferPoints);
				this.textureBokehMaterial.SetTexture("_MainTex", this.bokehTexture.texture);
				this.textureBokehMaterial.SetVector("_Screen", new Vector3(1f / (1f * (float)source.width), 1f / (1f * (float)source.height), num3));
				this.textureBokehMaterial.SetPass(0);
				Graphics.DrawProceduralIndirectNow(MeshTopology.Points, this.computeBufferDrawArgs, 0);
				Graphics.Blit(temporaryRenderTexture5, destination);
			}
			else
			{
				Graphics.Blit(source, destination, this.filmicDepthOfFieldMaterial, pass);
			}
		}

		// Token: 0x0600182C RID: 6188 RVA: 0x00067554 File Offset: 0x00065954
		private void DoHexagonalBlur(RenderTexture blurredFgCoc, ref RenderTexture src, ref RenderTexture dst, float maxRadius)
		{
			this.ComputeBlurDirections(false);
			int pass;
			int pass2;
			DepthOfField.GetDirectionalBlurPassesFromRadius(blurredFgCoc, maxRadius, out pass, out pass2);
			this.filmicDepthOfFieldMaterial.SetTexture("_SecondTex", blurredFgCoc);
			RenderTexture temporaryRenderTexture = this.m_RTU.GetTemporaryRenderTexture(src.width, src.height, 0, src.format, FilterMode.Bilinear);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_HexagonalBokehDirection1);
			Graphics.Blit(src, temporaryRenderTexture, this.filmicDepthOfFieldMaterial, pass);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_HexagonalBokehDirection2);
			Graphics.Blit(temporaryRenderTexture, src, this.filmicDepthOfFieldMaterial, pass);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_HexagonalBokehDirection3);
			this.filmicDepthOfFieldMaterial.SetTexture("_ThirdTex", src);
			Graphics.Blit(temporaryRenderTexture, dst, this.filmicDepthOfFieldMaterial, pass2);
			this.m_RTU.ReleaseTemporaryRenderTexture(temporaryRenderTexture);
			DepthOfField.SwapRenderTexture(ref src, ref dst);
		}

		// Token: 0x0600182D RID: 6189 RVA: 0x0006763C File Offset: 0x00065A3C
		private void DoOctogonalBlur(RenderTexture blurredFgCoc, ref RenderTexture src, ref RenderTexture dst, float maxRadius)
		{
			this.ComputeBlurDirections(false);
			int pass;
			int pass2;
			DepthOfField.GetDirectionalBlurPassesFromRadius(blurredFgCoc, maxRadius, out pass, out pass2);
			this.filmicDepthOfFieldMaterial.SetTexture("_SecondTex", blurredFgCoc);
			RenderTexture temporaryRenderTexture = this.m_RTU.GetTemporaryRenderTexture(src.width, src.height, 0, src.format, FilterMode.Bilinear);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_OctogonalBokehDirection1);
			Graphics.Blit(src, temporaryRenderTexture, this.filmicDepthOfFieldMaterial, pass);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_OctogonalBokehDirection2);
			Graphics.Blit(temporaryRenderTexture, dst, this.filmicDepthOfFieldMaterial, pass);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_OctogonalBokehDirection3);
			Graphics.Blit(src, temporaryRenderTexture, this.filmicDepthOfFieldMaterial, pass);
			this.filmicDepthOfFieldMaterial.SetVector("_Offsets", this.m_OctogonalBokehDirection4);
			this.filmicDepthOfFieldMaterial.SetTexture("_ThirdTex", dst);
			Graphics.Blit(temporaryRenderTexture, src, this.filmicDepthOfFieldMaterial, pass2);
			this.m_RTU.ReleaseTemporaryRenderTexture(temporaryRenderTexture);
		}

		// Token: 0x0600182E RID: 6190 RVA: 0x00067744 File Offset: 0x00065B44
		private void DoCircularBlur(RenderTexture blurredFgCoc, ref RenderTexture src, ref RenderTexture dst, float maxRadius)
		{
			int pass;
			if (blurredFgCoc != null)
			{
				this.filmicDepthOfFieldMaterial.SetTexture("_SecondTex", blurredFgCoc);
				pass = ((maxRadius <= 10f) ? 10 : 8);
			}
			else
			{
				pass = ((maxRadius <= 10f) ? 9 : 7);
			}
			Graphics.Blit(src, dst, this.filmicDepthOfFieldMaterial, pass);
			DepthOfField.SwapRenderTexture(ref src, ref dst);
		}

		// Token: 0x0600182F RID: 6191 RVA: 0x000677B4 File Offset: 0x00065BB4
		private void ComputeCocParameters(out Vector4 blurParams, out Vector4 blurCoe)
		{
			Camera component = base.GetComponent<Camera>();
			float num = this.focus.nearFalloff * 2f;
			float num2 = this.focus.farFalloff * 2f;
			float num3 = this.focus.nearPlane;
			float num4 = this.focus.farPlane;
			float num5;
			if (this.settings.tweakMode == DepthOfField.TweakMode.Range)
			{
				if (this.focus.transform != null)
				{
					num5 = component.WorldToViewportPoint(this.focus.transform.position).z;
				}
				else
				{
					num5 = this.focus.focusPlane;
				}
				float num6 = this.focus.range * 0.5f;
				num3 = num5 - num6;
				num4 = num5 + num6;
			}
			num3 -= num * 0.5f;
			num4 += num2 * 0.5f;
			num5 = (num3 + num4) * 0.5f;
			float num7 = num5 / component.farClipPlane;
			float num8 = num3 / component.farClipPlane;
			float num9 = num4 / component.farClipPlane;
			float num10 = num4 - num3;
			float num11 = num9 - num8;
			float num12 = num / num10;
			float num13 = num2 / num10;
			float num14 = (1f - num12) * (num11 * 0.5f);
			float num15 = (1f - num13) * (num11 * 0.5f);
			if (num7 <= num8)
			{
				num7 = num8 + 1E-06f;
			}
			if (num7 >= num9)
			{
				num7 = num9 - 1E-06f;
			}
			if (num7 - num14 <= num8)
			{
				num14 = num7 - num8 - 1E-06f;
			}
			if (num7 + num15 >= num9)
			{
				num15 = num9 - num7 - 1E-06f;
			}
			float num16 = 1f / (num8 - num7 + num14);
			float num17 = 1f / (num9 - num7 - num15);
			float num18 = 1f - num16 * num8;
			float num19 = 1f - num17 * num9;
			blurParams = new Vector4(-1f * num16, -1f * num18, 1f * num17, 1f * num19);
			blurCoe = new Vector4(0f, 0f, (num19 - num18) / (num16 - num17), 0f);
			this.focus.nearPlane = num3 + num * 0.5f;
			this.focus.farPlane = num4 - num2 * 0.5f;
			this.focus.focusPlane = (this.focus.nearPlane + this.focus.farPlane) * 0.5f;
			this.focus.range = this.focus.farPlane - this.focus.nearPlane;
		}

		// Token: 0x06001830 RID: 6192 RVA: 0x00067A4C File Offset: 0x00065E4C
		private void ReleaseComputeResources()
		{
			if (this.m_ComputeBufferDrawArgs != null)
			{
				this.m_ComputeBufferDrawArgs.Release();
			}
			if (this.m_ComputeBufferPoints != null)
			{
				this.m_ComputeBufferPoints.Release();
			}
			this.m_ComputeBufferDrawArgs = null;
			this.m_ComputeBufferPoints = null;
		}

		// Token: 0x06001831 RID: 6193 RVA: 0x00067A88 File Offset: 0x00065E88
		private void ComputeBlurDirections(bool force)
		{
			if (!force && Math.Abs(this.m_LastApertureOrientation - this.settings.apertureOrientation) < 1E-45f)
			{
				return;
			}
			this.m_LastApertureOrientation = this.settings.apertureOrientation;
			float num = this.settings.apertureOrientation * 0.017453292f;
			float cosinus = Mathf.Cos(num);
			float sinus = Mathf.Sin(num);
			this.m_OctogonalBokehDirection1 = new Vector4(0.5f, 0f, 0f, 0f);
			this.m_OctogonalBokehDirection2 = new Vector4(0f, 0.5f, 1f, 0f);
			this.m_OctogonalBokehDirection3 = new Vector4(-0.353553f, 0.353553f, 1f, 0f);
			this.m_OctogonalBokehDirection4 = new Vector4(0.353553f, 0.353553f, 1f, 0f);
			this.m_HexagonalBokehDirection1 = new Vector4(0.5f, 0f, 0f, 0f);
			this.m_HexagonalBokehDirection2 = new Vector4(0.25f, 0.433013f, 1f, 0f);
			this.m_HexagonalBokehDirection3 = new Vector4(0.25f, -0.433013f, 1f, 0f);
			if (num > 1E-45f)
			{
				DepthOfField.Rotate2D(ref this.m_OctogonalBokehDirection1, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_OctogonalBokehDirection2, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_OctogonalBokehDirection3, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_OctogonalBokehDirection4, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_HexagonalBokehDirection1, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_HexagonalBokehDirection2, cosinus, sinus);
				DepthOfField.Rotate2D(ref this.m_HexagonalBokehDirection3, cosinus, sinus);
			}
		}

		// Token: 0x170001FB RID: 507
		// (get) Token: 0x06001832 RID: 6194 RVA: 0x00067C2D File Offset: 0x0006602D
		private bool shouldPerformBokeh
		{
			get
			{
				return ImageEffectHelper.supportsDX11 && this.bokehTexture.texture != null && this.textureBokehMaterial;
			}
		}

		// Token: 0x06001833 RID: 6195 RVA: 0x00067C60 File Offset: 0x00066060
		private static void Rotate2D(ref Vector4 direction, float cosinus, float sinus)
		{
			Vector4 vector = direction;
			direction.x = vector.x * cosinus - vector.y * sinus;
			direction.y = vector.x * sinus + vector.y * cosinus;
		}

		// Token: 0x06001834 RID: 6196 RVA: 0x00067CA8 File Offset: 0x000660A8
		private static void SwapRenderTexture(ref RenderTexture src, ref RenderTexture dst)
		{
			RenderTexture renderTexture = dst;
			dst = src;
			src = renderTexture;
		}

		// Token: 0x06001835 RID: 6197 RVA: 0x00067CC0 File Offset: 0x000660C0
		private static void GetDirectionalBlurPassesFromRadius(RenderTexture blurredFgCoc, float maxRadius, out int blurPass, out int blurAndMergePass)
		{
			if (blurredFgCoc == null)
			{
				if (maxRadius > 10f)
				{
					blurPass = 20;
					blurAndMergePass = 22;
				}
				else if (maxRadius > 5f)
				{
					blurPass = 16;
					blurAndMergePass = 18;
				}
				else
				{
					blurPass = 12;
					blurAndMergePass = 14;
				}
			}
			else if (maxRadius > 10f)
			{
				blurPass = 21;
				blurAndMergePass = 23;
			}
			else if (maxRadius > 5f)
			{
				blurPass = 17;
				blurAndMergePass = 19;
			}
			else
			{
				blurPass = 13;
				blurAndMergePass = 15;
			}
		}

		// Token: 0x04000D6F RID: 3439
		private const float kMaxBlur = 40f;

		// Token: 0x04000D70 RID: 3440
		public DepthOfField.GlobalSettings settings = DepthOfField.GlobalSettings.defaultSettings;

		// Token: 0x04000D71 RID: 3441
		public DepthOfField.FocusSettings focus = DepthOfField.FocusSettings.defaultSettings;

		// Token: 0x04000D72 RID: 3442
		public DepthOfField.BokehTextureSettings bokehTexture = DepthOfField.BokehTextureSettings.defaultSettings;

		// Token: 0x04000D73 RID: 3443
		[SerializeField]
		private Shader m_FilmicDepthOfFieldShader;

		// Token: 0x04000D74 RID: 3444
		[SerializeField]
		private Shader m_MedianFilterShader;

		// Token: 0x04000D75 RID: 3445
		[SerializeField]
		private Shader m_TextureBokehShader;

		// Token: 0x04000D76 RID: 3446
		private RenderTextureUtility m_RTU = new RenderTextureUtility();

		// Token: 0x04000D77 RID: 3447
		private Material m_FilmicDepthOfFieldMaterial;

		// Token: 0x04000D78 RID: 3448
		private Material m_MedianFilterMaterial;

		// Token: 0x04000D79 RID: 3449
		private Material m_TextureBokehMaterial;

		// Token: 0x04000D7A RID: 3450
		private ComputeBuffer m_ComputeBufferDrawArgs;

		// Token: 0x04000D7B RID: 3451
		private ComputeBuffer m_ComputeBufferPoints;

		// Token: 0x04000D7C RID: 3452
		private DepthOfField.QualitySettings m_CurrentQualitySettings;

		// Token: 0x04000D7D RID: 3453
		private float m_LastApertureOrientation;

		// Token: 0x04000D7E RID: 3454
		private Vector4 m_OctogonalBokehDirection1;

		// Token: 0x04000D7F RID: 3455
		private Vector4 m_OctogonalBokehDirection2;

		// Token: 0x04000D80 RID: 3456
		private Vector4 m_OctogonalBokehDirection3;

		// Token: 0x04000D81 RID: 3457
		private Vector4 m_OctogonalBokehDirection4;

		// Token: 0x04000D82 RID: 3458
		private Vector4 m_HexagonalBokehDirection1;

		// Token: 0x04000D83 RID: 3459
		private Vector4 m_HexagonalBokehDirection2;

		// Token: 0x04000D84 RID: 3460
		private Vector4 m_HexagonalBokehDirection3;

		// Token: 0x02000478 RID: 1144
		private enum Passes
		{
			// Token: 0x04000D86 RID: 3462
			BlurAlphaWeighted,
			// Token: 0x04000D87 RID: 3463
			BoxBlur,
			// Token: 0x04000D88 RID: 3464
			DilateFgCocFromColor,
			// Token: 0x04000D89 RID: 3465
			DilateFgCoc,
			// Token: 0x04000D8A RID: 3466
			CaptureCocExplicit,
			// Token: 0x04000D8B RID: 3467
			VisualizeCocExplicit,
			// Token: 0x04000D8C RID: 3468
			CocPrefilter,
			// Token: 0x04000D8D RID: 3469
			CircleBlur,
			// Token: 0x04000D8E RID: 3470
			CircleBlurWithDilatedFg,
			// Token: 0x04000D8F RID: 3471
			CircleBlurLowQuality,
			// Token: 0x04000D90 RID: 3472
			CircleBlowLowQualityWithDilatedFg,
			// Token: 0x04000D91 RID: 3473
			MergeExplicit,
			// Token: 0x04000D92 RID: 3474
			ShapeLowQuality,
			// Token: 0x04000D93 RID: 3475
			ShapeLowQualityDilateFg,
			// Token: 0x04000D94 RID: 3476
			ShapeLowQualityMerge,
			// Token: 0x04000D95 RID: 3477
			ShapeLowQualityMergeDilateFg,
			// Token: 0x04000D96 RID: 3478
			ShapeMediumQuality,
			// Token: 0x04000D97 RID: 3479
			ShapeMediumQualityDilateFg,
			// Token: 0x04000D98 RID: 3480
			ShapeMediumQualityMerge,
			// Token: 0x04000D99 RID: 3481
			ShapeMediumQualityMergeDilateFg,
			// Token: 0x04000D9A RID: 3482
			ShapeHighQuality,
			// Token: 0x04000D9B RID: 3483
			ShapeHighQualityDilateFg,
			// Token: 0x04000D9C RID: 3484
			ShapeHighQualityMerge,
			// Token: 0x04000D9D RID: 3485
			ShapeHighQualityMergeDilateFg
		}

		// Token: 0x02000479 RID: 1145
		private enum MedianPasses
		{
			// Token: 0x04000D9F RID: 3487
			Median3,
			// Token: 0x04000DA0 RID: 3488
			Median3X3
		}

		// Token: 0x0200047A RID: 1146
		private enum BokehTexturesPasses
		{
			// Token: 0x04000DA2 RID: 3490
			Apply,
			// Token: 0x04000DA3 RID: 3491
			Collect
		}

		// Token: 0x0200047B RID: 1147
		public enum TweakMode
		{
			// Token: 0x04000DA5 RID: 3493
			Range,
			// Token: 0x04000DA6 RID: 3494
			Explicit
		}

		// Token: 0x0200047C RID: 1148
		public enum ApertureShape
		{
			// Token: 0x04000DA8 RID: 3496
			Circular,
			// Token: 0x04000DA9 RID: 3497
			Hexagonal,
			// Token: 0x04000DAA RID: 3498
			Octogonal
		}

		// Token: 0x0200047D RID: 1149
		public enum QualityPreset
		{
			// Token: 0x04000DAC RID: 3500
			Low,
			// Token: 0x04000DAD RID: 3501
			Medium,
			// Token: 0x04000DAE RID: 3502
			High
		}

		// Token: 0x0200047E RID: 1150
		public enum FilterQuality
		{
			// Token: 0x04000DB0 RID: 3504
			None,
			// Token: 0x04000DB1 RID: 3505
			Normal,
			// Token: 0x04000DB2 RID: 3506
			High
		}

		// Token: 0x0200047F RID: 1151
		[Serializable]
		public struct GlobalSettings
		{
			// Token: 0x170001FC RID: 508
			// (get) Token: 0x06001836 RID: 6198 RVA: 0x00067D50 File Offset: 0x00066150
			public static DepthOfField.GlobalSettings defaultSettings
			{
				get
				{
					return new DepthOfField.GlobalSettings
					{
						visualizeFocus = false,
						tweakMode = DepthOfField.TweakMode.Range,
						filteringQuality = DepthOfField.QualityPreset.High,
						apertureShape = DepthOfField.ApertureShape.Circular,
						apertureOrientation = 0f
					};
				}
			}

			// Token: 0x04000DB3 RID: 3507
			[Tooltip("Allows to view where the blur will be applied. Yellow for near blur, blue for far blur.")]
			public bool visualizeFocus;

			// Token: 0x04000DB4 RID: 3508
			[Tooltip("Setup mode. Use \"Advanced\" if you need more control on blur settings and/or want to use a bokeh texture. \"Explicit\" is the same as \"Advanced\" but makes use of \"Near Plane\" and \"Far Plane\" values instead of \"F-Stop\".")]
			public DepthOfField.TweakMode tweakMode;

			// Token: 0x04000DB5 RID: 3509
			[Tooltip("Quality presets. Use \"Custom\" for more advanced settings.")]
			public DepthOfField.QualityPreset filteringQuality;

			// Token: 0x04000DB6 RID: 3510
			[Tooltip("\"Circular\" is the fastest, followed by \"Hexagonal\" and \"Octogonal\".")]
			public DepthOfField.ApertureShape apertureShape;

			// Token: 0x04000DB7 RID: 3511
			[Range(0f, 179f)]
			[Tooltip("Rotates the aperture when working with \"Hexagonal\" and \"Ortogonal\".")]
			public float apertureOrientation;
		}

		// Token: 0x02000480 RID: 1152
		[Serializable]
		public struct QualitySettings
		{
			// Token: 0x04000DB8 RID: 3512
			[Tooltip("Enable this to get smooth bokeh.")]
			public bool prefilterBlur;

			// Token: 0x04000DB9 RID: 3513
			[Tooltip("Applies a median filter for even smoother bokeh.")]
			public DepthOfField.FilterQuality medianFilter;

			// Token: 0x04000DBA RID: 3514
			[Tooltip("Dilates near blur over in focus area.")]
			public bool dilateNearBlur;

			// Token: 0x04000DBB RID: 3515
			public static DepthOfField.QualitySettings[] presetQualitySettings = new DepthOfField.QualitySettings[]
			{
				new DepthOfField.QualitySettings
				{
					prefilterBlur = false,
					medianFilter = DepthOfField.FilterQuality.None,
					dilateNearBlur = false
				},
				new DepthOfField.QualitySettings
				{
					prefilterBlur = true,
					medianFilter = DepthOfField.FilterQuality.Normal,
					dilateNearBlur = false
				},
				new DepthOfField.QualitySettings
				{
					prefilterBlur = true,
					medianFilter = DepthOfField.FilterQuality.High,
					dilateNearBlur = true
				}
			};
		}

		// Token: 0x02000481 RID: 1153
		[Serializable]
		public struct FocusSettings
		{
			// Token: 0x170001FD RID: 509
			// (get) Token: 0x06001838 RID: 6200 RVA: 0x00067E34 File Offset: 0x00066234
			public static DepthOfField.FocusSettings defaultSettings
			{
				get
				{
					return new DepthOfField.FocusSettings
					{
						transform = null,
						focusPlane = 20f,
						range = 35f,
						nearPlane = 2.5f,
						nearFalloff = 15f,
						farPlane = 37.5f,
						farFalloff = 50f,
						nearBlurRadius = 15f,
						farBlurRadius = 20f
					};
				}
			}

			// Token: 0x04000DBC RID: 3516
			[Tooltip("Auto-focus on a selected transform.")]
			public Transform transform;

			// Token: 0x04000DBD RID: 3517
			[Min(0f)]
			[Tooltip("Focus distance (in world units).")]
			public float focusPlane;

			// Token: 0x04000DBE RID: 3518
			[Min(0.1f)]
			[Tooltip("Focus range (in world units). The focus plane is located in the center of the range.")]
			public float range;

			// Token: 0x04000DBF RID: 3519
			[Min(0f)]
			[Tooltip("Near focus distance (in world units).")]
			public float nearPlane;

			// Token: 0x04000DC0 RID: 3520
			[Min(0f)]
			[Tooltip("Near blur falloff (in world units).")]
			public float nearFalloff;

			// Token: 0x04000DC1 RID: 3521
			[Min(0f)]
			[Tooltip("Far focus distance (in world units).")]
			public float farPlane;

			// Token: 0x04000DC2 RID: 3522
			[Min(0f)]
			[Tooltip("Far blur falloff (in world units).")]
			public float farFalloff;

			// Token: 0x04000DC3 RID: 3523
			[Range(0f, 40f)]
			[Tooltip("Maximum blur radius for the near plane.")]
			public float nearBlurRadius;

			// Token: 0x04000DC4 RID: 3524
			[Range(0f, 40f)]
			[Tooltip("Maximum blur radius for the far plane.")]
			public float farBlurRadius;
		}

		// Token: 0x02000482 RID: 1154
		[Serializable]
		public struct BokehTextureSettings
		{
			// Token: 0x170001FE RID: 510
			// (get) Token: 0x06001839 RID: 6201 RVA: 0x00067EB4 File Offset: 0x000662B4
			public static DepthOfField.BokehTextureSettings defaultSettings
			{
				get
				{
					return new DepthOfField.BokehTextureSettings
					{
						texture = null,
						scale = 1f,
						intensity = 50f,
						threshold = 2f,
						spawnHeuristic = 0.15f
					};
				}
			}

			// Token: 0x04000DC5 RID: 3525
			[Tooltip("Adding a texture to this field will enable the use of \"Bokeh Textures\". Use with care. This feature is only available on Shader Model 5 compatible-hardware and performance scale with the amount of bokeh.")]
			public Texture2D texture;

			// Token: 0x04000DC6 RID: 3526
			[Range(0.01f, 10f)]
			[Tooltip("Maximum size of bokeh textures on screen.")]
			public float scale;

			// Token: 0x04000DC7 RID: 3527
			[Range(0.01f, 100f)]
			[Tooltip("Bokeh brightness.")]
			public float intensity;

			// Token: 0x04000DC8 RID: 3528
			[Range(0.01f, 5f)]
			[Tooltip("Controls the amount of bokeh textures. Lower values mean more bokeh splats.")]
			public float threshold;

			// Token: 0x04000DC9 RID: 3529
			[Range(0.01f, 1f)]
			[Tooltip("Controls the spawn conditions. Lower values mean more visible bokeh.")]
			public float spawnHeuristic;
		}
	}
}
